const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    singnav: [],
    page:1,
    pageSize:10,
    isEnd:false,
    title:"栏目",
    inputValue:'',
    singnavleft:[],
    singnavright:[],
    isloading:false,
  },
  onLoad: function (options) {

  },
  onReady() {
    this.Dialog = this.selectComponent('#Dialog');
    this.categoryListover()
  },
  categoryListover(){
    Controller.categoryList({
      keyword:this.data.inputValue,
      page:this.data.page,
      pageSize:this.data.pageSize,
      isIndex:'',
    }).then(res => {
      if(res.data.baseData.list.length>0){
        this.setData({
          singnav:this.data.singnav.concat(res.data.baseData.list)
        })
        let singnavleft = [];
        let singnavright = [];

        if (this.data.singnav && this.data.singnav.length > 0) {
          for (let i = 0; i < this.data.singnav.length; i++) {
            if (i % 2 == 0) {
              singnavleft.push(this.data.singnav[i])
            } else {
              singnavright.push(this.data.singnav[i])
            }
          }
        }
        this.setData({
          singnavleft: singnavleft,
          singnavright: singnavright
        })

        if(res.data.baseData.lastPage){
          this.setData({
            isEnd:true
          })
        }
      }
      this.setData({isloading:true})
      
    }).catch(res=>{
      this.setData({isloading:true})
    })
  },
  scrollend(){
    if(!this.data.isEnd){
      this.setData({
        page:this.data.page+1
      })
      this.categoryListover()
    }
  },
  tosearch() {
    wx.navigateTo({
      url: '/pages/column/Search'
    })
  },
  searchSubmit(e){
    console.log(e)
    let _SearchValue = e.target.dataset.search;
    
    this.setData({
      singnav: [],
      page:1,
      pageSize:10,
      isEnd:false,
    })
    this.categoryListover()

  },
  bindInput(e){
    var value=e.detail.value || ''
    this.setData({
      inputValue: value
    })
  },
  PopSlowSongs(e){
    var categoryId=e.currentTarget.dataset.categoryid;
    var tag=e.currentTarget.dataset.tag;
    wx.navigateTo({
      url: "/pages/PopSlowSongs/PopSlowSongs?id=" + categoryId + "&title=" + tag
    })
  },
  onShareAppMessage: function (e) {
    // if (e.from == "button") {
      let obj = {
        title: '有氧FM·栏目',
        success: function (res) {
          
        },
        fail(err) {
          
        }
      }
      return obj
    // }
  },
  onShareTimeline: function (e) {
    // if (e.from == "button") {
      let obj = {
        title: '有氧FM·栏目',
        success: function (res) {
          
        },
        fail(err) {
          
        }
      }
      return obj
    // }
  },
})